/*
 * Copyright (c) 2016. zhaojin 15398699939@163.com
 */

package com.bankscene.screenfit.vus;

import android.support.design.widget.NavigationView;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.bankscene.screenfit.R;

public class MainVu implements Vu {

    View view;
    FrameLayout containerView;
    DrawerLayout mDrawerLayout;
    Toolbar toolbar;
    private VuCallback<Integer> navigationItemSelectedCallback;

    @Override
    public void init(LayoutInflater inflater, ViewGroup container) {
        view = inflater.inflate(R.layout.activity_main, container, false);
        containerView = (FrameLayout) view.findViewById(R.id.contentFrame);
        toolbar = (Toolbar) view.findViewById(R.id.toolbar);

        // Set up the navigation drawer.
        mDrawerLayout = (DrawerLayout) view.findViewById(R.id.drawer_layout);
        mDrawerLayout.setStatusBarBackground(R.color.colorPrimaryDark);
        final NavigationView navigationView = (NavigationView) view.findViewById(R.id.nav_view);
        if (navigationView != null) {
            setupDrawerContent(navigationView);
        }
    }


    private void setupDrawerContent(NavigationView navigationView) {
        navigationView.setNavigationItemSelectedListener(
                new NavigationView.OnNavigationItemSelectedListener() {
                    @Override
                    public boolean onNavigationItemSelected(MenuItem menuItem) {
                        if (null != navigationItemSelectedCallback) {
                            navigationItemSelectedCallback.execute(menuItem.getItemId());
                        }
                        // Close the navigation drawer when an item is selected.
                        menuItem.setChecked(true);
                        mDrawerLayout.closeDrawers();
                        return true;
                    }
                });
    }

    @Override
    public View getView() {
        return view;
    }

    public int getContainerId() {
        return containerView.getId();
    }

    public Toolbar getActionBar() {
        return toolbar;
    }

    public DrawerLayout getDrawerLayout() {
        return mDrawerLayout;
    }

    public void setNavigationItemSelectedCallback(VuCallback<Integer> navigationItemSelectedCallback) {
        this.navigationItemSelectedCallback = navigationItemSelectedCallback;
    }
}
